import { Body, Controller, Delete, Get, Param, Patch, Post } from '@nestjs/common';
import { AccountEntity } from 'src/account/entities/account.entity';
import { AccountService } from 'src/account/services/account/account.service';
import { DeleteResult, UpdateResult } from 'typeorm';

@Controller('account')
export class AccountController {
  constructor (
    private readonly accountService: AccountService,
  ) { }

  // 创建账号
  @Post()
  async createAccount(
    @Body() data: any,
  ): Promise<any> {
    return await this.accountService.createAccount(data);
  }

  @Delete(':id')
  async deleteAccountById(
    @Param('id') id: number
  ): Promise<DeleteResult> {
    return await this.accountService.deleteAccountById(id);
  }

  @Patch(':id')
  async modifyAccountById(
    @Param('id') id: number,
    @Body() data: any,
  ): Promise<UpdateResult> {
    return await this.accountService.modifyAccountById(id, data);
  }

  @Get()
  async accountList():Promise<AccountEntity[]> {
    return this.accountService.accountList();
  }
}
